package rpc

import (
	"round_game/common"
	"round_game/common/proto/game"
)

func (r *RPC) Fight(attack, defend map[uint32]*game.Hero) (reply *game.BattleResp, err error) {
	args := &game.BattleReq{
		Hero: make(map[uint32]*game.Hero),
	}
	for k, v := range attack { //FillCamp(attack,0){
		args.Hero[k] = v
	}
	for k, v := range FillCamp(defend, 1) {
		args.Hero[k] = v
	}
	reply = &game.BattleResp{}
	err = r.Call(common.FIGHT, "GetBattleResult", args, reply)
	//FillCamp(attack,0)
	FillCamp(defend, 0)
	return
}

func FillCamp(hero map[uint32]*game.Hero, camp int32) map[uint32]*game.Hero {
	for _, v := range hero {
		v.Camp = game.FightCamp(camp)
	}
	return hero
}
